
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.2.3 数组 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="guifan.html" />
    
    
    <link rel="prev" href="map.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    理想未死
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    1. java基础
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" >
            
                <span>
            
                    
                    1.1 数据类型
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="string.html">
            
                <a href="string.html">
            
                    
                    1.1.1 字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="num.html">
            
                <a href="num.html">
            
                    
                    1.1.2 数字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="date.html">
            
                <a href="date.html">
            
                    
                    1.1.3 日期
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" >
            
                <span>
            
                    
                    1.2 集合
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="list.html">
            
                <a href="list.html">
            
                    
                    1.2.1 list
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="map.html">
            
                <a href="map.html">
            
                    
                    1.2.2 map
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.2.3" data-path="arr.html">
            
                <a href="arr.html">
            
                    
                    1.2.3 数组
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="guifan.html">
            
                <a href="guifan.html">
            
                    
                    1.3 编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    2. 版本控制
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../git.html">
            
                <a href="../git.html">
            
                    
                    2.1 git
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../gradle.html">
            
                <a href="../gradle.html">
            
                    
                    2.4 gradle
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    3. 常用技术
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../patzn/poi.md">
            
                <span>
            
                    
                    3.1 poi
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="../poi.html">
            
                <a href="../poi.html">
            
                    
                    3.1.1 原生poi
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="../poi.html">
            
                <a href="../poi.html">
            
                    
                    3.1.2 easypoi
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    4. 常用框架
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../example2.md">
            
                <span>
            
                    
                    4.1 springboot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../patzn/mybatis.md">
            
                <span>
            
                    
                    4.2 mybatisPlus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../ali.html">
            
                <a href="../ali.html">
            
                    
                    4.3 spring cloud alibaba
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    5. 中间件
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../rocket.md">
            
                <span>
            
                    
                    5.1 rockermq
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" >
            
                <span>
            
                    
                    5.2 Arthas(线上诊断工具)
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../jvm.html">
            
                <a href="../jvm.html">
            
                    
                    6. jvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../example2.md">
            
                <span>
            
                    
                    7. 设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../patzn/readme.md">
            
                <span>
            
                    
                    8. 工具类
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../patzn/upload.md">
            
                <span>
            
                    
                    8.1 上传&下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../patzn/input.md">
            
                <span>
            
                    
                    8.2 导入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../patzn/debris.md">
            
                <span>
            
                    
                    8.3 其他
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" >
            
                <span>
            
                    
                    9. 前端
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../../js/debris.html">
            
                <a href="../../js/debris.html">
            
                    
                    9.1 碎片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../example2.md">
            
                <span>
            
                    
                    9.2 vue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../example2.md">
            
                <span>
            
                    
                    9.3 react
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../example2.md">
            
                <span>
            
                    
                    9.4 node.js
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" >
            
                <span>
            
                    
                    10. 数据库
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../../sql/mysql.html">
            
                <a href="../../sql/mysql.html">
            
                    
                    10.1 设计规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../../sql/pgsql.html">
            
                <a href="../../sql/pgsql.html">
            
                    
                    10.2 常用函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../../sql/design.html">
            
                <a href="../../sql/design.html">
            
                    
                    10.3 海量数据处理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" >
            
                <span>
            
                    
                    11. 运维
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../../linux/linux.html">
            
                <a href="../../linux/linux.html">
            
                    
                    11.1 linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" >
            
                <span>
            
                    
                    11.2 docker
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.2.1" data-path="../../linux/docker_basic.html">
            
                <a href="../../linux/docker_basic.html">
            
                    
                    11.2.1 基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2.2" data-path="../../linux/docker_pro.html">
            
                <a href="../../linux/docker_pro.html">
            
                    
                    11.2.2 进阶
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../../linux/nginx.html">
            
                <a href="../../linux/nginx.html">
            
                    
                    11.3 nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../../linux/jenkins.html">
            
                <a href="../../linux/jenkins.html">
            
                    
                    11.4 jenkins
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../../mac/experience.html">
            
                <a href="../../mac/experience.html">
            
                    
                    12. 操作系统
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >1.2.3 数组</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <blockquote>
<p><strong>&#x3010;&#x5F3A;&#x5236;&#x3011;&#x4F7F;&#x7528;&#x96C6;&#x5408;&#x8F6C;&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5FC5;&#x987B;&#x4F7F;&#x7528;&#x96C6;&#x5408;&#x7684; toArray(T[] array)&#xFF0C;&#x4F20;&#x5165;&#x7684;&#x662F;&#x7C7B;&#x578B;&#x5B8C;&#x5168;&#x4E00;
&#x81F4;&#x3001;&#x957F;&#x5EA6;&#x4E3A; 0 &#x7684;&#x7A7A;&#x6570;&#x7EC4;&#x3002;</strong></p>
</blockquote>
<pre><code class="lang-java">&#x53CD;&#x4F8B;&#xFF1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528; toArray &#x65E0;&#x53C2;&#x65B9;&#x6CD5;&#x5B58;&#x5728;&#x95EE;&#x9898;&#xFF0C;&#x6B64;&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x503C;&#x53EA;&#x80FD;&#x662F; Object[]&#x7C7B;&#xFF0C;&#x82E5;&#x5F3A;&#x8F6C;&#x5176;&#x5B83;&#x7C7B;&#x578B;&#x6570;&#x7EC4;&#x5C06;&#x51FA;&#x73B0;
ClassCastException &#x9519;&#x8BEF;&#x3002;
&#x6B63;&#x4F8B;&#xFF1A;
List&lt;String&gt; list = <span class="hljs-keyword">new</span> ArrayList&lt;&gt;(<span class="hljs-number">2</span>);
list.add(<span class="hljs-string">&quot;guan&quot;</span>);
list.add(<span class="hljs-string">&quot;bao&quot;</span>);
String[] array = list.toArray(<span class="hljs-keyword">new</span> String[<span class="hljs-number">0</span>]);
&#x8BF4;&#x660E;&#xFF1A;&#x4F7F;&#x7528; toArray &#x5E26;&#x53C2;&#x65B9;&#x6CD5;&#xFF0C;&#x6570;&#x7EC4;&#x7A7A;&#x95F4;&#x5927;&#x5C0F;&#x7684; length&#xFF1A; <span class="hljs-number">1</span>&#xFF09; &#x7B49;&#x4E8E; <span class="hljs-number">0</span>&#xFF0C;&#x52A8;&#x6001;&#x521B;&#x5EFA;&#x4E0E; size &#x76F8;&#x540C;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x6027;&#x80FD;&#x6700;&#x597D;&#x3002;
<span class="hljs-number">2</span>&#xFF09; &#x5927;&#x4E8E; <span class="hljs-number">0</span> &#x4F46;&#x5C0F;&#x4E8E; size&#xFF0C;&#x91CD;&#x65B0;&#x521B;&#x5EFA;&#x5927;&#x5C0F;&#x7B49;&#x4E8E; size &#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x589E;&#x52A0; GC &#x8D1F;&#x62C5;&#x3002;
<span class="hljs-number">3</span>&#xFF09; &#x7B49;&#x4E8E; size&#xFF0C;&#x5728;&#x9AD8;&#x5E76;&#x53D1;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6570;&#x7EC4;&#x521B;&#x5EFA;&#x5B8C;&#x6210;&#x4E4B;&#x540E;&#xFF0C;size &#x6B63;&#x5728;&#x53D8;&#x5927;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8D1F;&#x9762;&#x5F71;&#x54CD;&#x4E0E; <span class="hljs-number">2</span> &#x76F8;&#x540C;&#x3002;
<span class="hljs-number">4</span>&#xFF09; &#x5927;&#x4E8E; size&#xFF0C;&#x7A7A;&#x95F4;&#x6D6A;&#x8D39;&#xFF0C;&#x4E14;&#x5728; size &#x5904;&#x63D2;&#x5165; <span class="hljs-keyword">null</span> &#x503C;&#xFF0C;&#x5B58;&#x5728; NPE &#x9690;&#x60A3;&#x3002;
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="map.html" class="navigation navigation-prev " aria-label="Previous page: 1.2.2 map">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="guifan.html" class="navigation navigation-next " aria-label="Next page: 1.3 编码规范">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.2.3 数组","level":"1.2.2.3","depth":3,"next":{"title":"1.3 编码规范","level":"1.2.3","depth":2,"path":"java/basic/guifan.md","ref":"java/basic/guifan.md","articles":[]},"previous":{"title":"1.2.2 map","level":"1.2.2.2","depth":3,"path":"java/basic/map.md","ref":"java/basic/map.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"java/basic/arr.md","mtime":"2021-02-11T01:30:34.332Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-03-20T06:16:02.011Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

